package containers;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class Page {
	private String myURLString;
	private URL myURL;
	private String myContents;
	private List<String> myWords;
	private int myNumLinks;
	private long myParseTime;
	private ArrayList<URL> myURLs;
	
	/**
	 * Constructor.
	 * Constructs a retrieved page.
	 */
	public Page(final URL theURL) {
		myURLString = new String();
		myContents = new String();
		myNumLinks = 0;
		myParseTime = 0;
		myURL = theURL;
		myURLs = new ArrayList<URL>();
	}
	
	public void buildRetrievedPage(final String theURL, final String theContents) {
		myURLString = theURL;
		myContents = theContents;
	}
	
	//set by PageParser
	public void setWords(final List<String> words) {
		myWords = words;
	}
	
	//this will be set by PageParser
	public void setLinkNumber(final int theNumLinks) {
		myNumLinks = theNumLinks;
	}
	
	public void setParseTime(final long theTime) {
		myParseTime = theTime;
	}
	
	public String getURLString() {
		return myURLString;
	}
	
	public URL getURL() {
		return myURL;
	}
	
	public String getContents() {
		return myContents;
	}
	
	public List<String> getWords() {
		return myWords;
	}
	
	public long getParseTime() {
		return myParseTime;
	}
	
	//assuming "Average URLs per page" includes links already visited
	//this number will be set by PageParser and retrieved by PageAnalyzer
	public int getNumLinks() {
		return myNumLinks;
	}
	
	public void setURLs(final List<URL> urls) {
		myURLs = (ArrayList<URL>) urls;
	}
	
	public ArrayList<URL> getURLs() {
		return myURLs;
	}
	
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("Page url: ");
		sb.append(myURLString);
		sb.append("\twords: ");
		sb.append(myContents);
		sb.append("\turls: ");
		sb.append(myURLs);
		sb.append("\n");
		
		
		return sb.toString();
	}
}
